﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace PoemonAdventures
{
    public class Camera2D
    {
        public float m_zoom = 1f;
        public Vector2 m_pos = new Vector2(0, 0);
        public float m_rotation;

        public Matrix TransformMatrix
        {
            get
            {
                return Matrix.CreateScale(m_zoom) * Matrix.CreateRotationZ(m_rotation) * Matrix.CreateTranslation(new Vector3(-m_pos, 0f));
            }

        }

        public void Update()
        {
            KeyboardState ks = Keyboard.GetState();
            if (ks.IsKeyDown(Keys.W))
            {
                m_pos.Y -= 2.0f;
            }
            else if (ks.IsKeyDown(Keys.A))
            {
                m_pos.X -= 2.0f;
            }
            else if (ks.IsKeyDown(Keys.S))
            {
                m_pos.Y += 2.0f;
            }

            else if (ks.IsKeyDown(Keys.D))
            {
                m_pos.X += 2.0f;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, TransformMatrix);
            spriteBatch.End();
        }
    }
}
